package org.fastsyncer.connector.mysql;

import org.fastsyncer.connector.config.DatabaseConfig;
import org.fastsyncer.connector.config.SqlConfig;
import org.fastsyncer.connector.constant.DatabaseConstant;
import org.fastsyncer.connector.database.AbstractDatabaseConnector;

public final class MysqlConnector extends AbstractDatabaseConnector {

	@Override
	public SqlConfig getSqlConfig(DatabaseConfig config, String table, String queryFilter) {
		// 查询元信息 SELECT * FROM USER LIMIT 0
		String metaSQL = new StringBuilder().append("SELECT * FROM ").append(table)
				.append(DatabaseConstant.MYSQL_PAGE_SQL_NULL).toString();
		// 求数据总量 SELECT * FROM USER WHERE ID='123'
		String countSQL = new StringBuilder().append("SELECT * FROM ").append(table).append(queryFilter).toString();
		return new SqlConfig(metaSQL, countSQL);
	}

	@Override
	public String getPageSql(DatabaseConfig config, String table, String sql) {
		// Mysql 分页查询
		return sql + DatabaseConstant.MYSQL_PAGE_SQL;
	}

}
